package com.derbysoft.ota.application.translator.rs;

import java.util.Map;

import com.derbysoft.modules.eip.translator.Translator;
import com.derbysoft.ota.interfaces.protocol._2009a.HotelResResponseType;
import com.derbysoft.ota.interfaces.protocol._2009a.HotelReservationType;
import com.derbysoft.ota.interfaces.protocol._2009a.HotelReservationsType;
import com.derbysoft.ota.interfaces.protocol._2009a.TransactionStatusType;
import com.derbysoft.remote.dswitch.hotel.dto.HotelReservationRS;
import com.google.common.collect.Maps;
import com.google.inject.Inject;


public class HotelReservationRSTranslator implements 
	Translator<HotelResResponseTypeSource, HotelResResponseType> {

	private Translator<com.derbysoft.remote.dswitch.generic.constants.TransactionStatusType, TransactionStatusType> transactionStatusTypeTranslator;
	private Translator<Map.Entry<HotelReservationRS, HotelReservationType>, HotelReservationType> hotelReservationTypeRSTranslator;
	
	@Inject
	public HotelReservationRSTranslator(
		Translator<com.derbysoft.remote.dswitch.generic.constants.TransactionStatusType, TransactionStatusType> transactionStatusTypeTranslator,
		Translator<Map.Entry<HotelReservationRS, HotelReservationType>, HotelReservationType> hotelReservationTypeRSTranslator) {

		this.transactionStatusTypeTranslator = transactionStatusTypeTranslator;
		this.hotelReservationTypeRSTranslator = hotelReservationTypeRSTranslator;
	}


	@Override
	public HotelResResponseType translate(HotelResResponseTypeSource source) {
		HotelResResponseType existedOtaRS = source.getOtaRS();
		HotelReservationRS switchRS = source.getSwitchRS();
		existedOtaRS.setResResponseType(responseType(switchRS.getResStatusType()));
		existedOtaRS.setHotelReservations(new HotelReservationsType());
		existedOtaRS.getHotelReservations().getHotelReservation().add(reservation(switchRS, source.getRequestedReservation()));
		return existedOtaRS;
	}



	private TransactionStatusType responseType(
		com.derbysoft.remote.dswitch.generic.constants.TransactionStatusType resStatusType) {

		return transactionStatusTypeTranslator.translate(resStatusType);
	}

	private HotelReservationType reservation(HotelReservationRS switchRS, HotelReservationType otaRQ) {
		return hotelReservationTypeRSTranslator.translate(Maps.immutableEntry(switchRS, otaRQ));
	}
	
}
